﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using YmSoft.Kblog.Model;


namespace YmSoft.Kblog.Module
{
    public class LimitLoginModule : IHttpModule
    {

        #region 禁止登录带时间控制自动解封

        public void Dispose()
        {

        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        void context_BeginRequest(object app, EventArgs e)
        {
            HttpApplication application = (HttpApplication)app;
            HttpContext context = application.Context;
            YmSoft.Kblog.Model.K_LimitIP k_LimitIP = new YmSoft.Kblog.Model.K_LimitIP();
            YmSoft.Kblog.BLL.LimitIPManager blllimitIPManager = new YmSoft.Kblog.BLL.LimitIPManager();
            List<K_LimitIP> limitList = blllimitIPManager.GetAllLimitIP();
            if (limitList != null)
            {
                foreach (K_LimitIP list in limitList)
                {
                    if (list.IP.Equals(context.Request.UserHostAddress))
                    {
                        context.Response.Write(string.Format("您的IP地址：<font color='red'> {0} </font>，禁止访问！<br/><br/><br/> 操作人：{1}<br/>原因：{2}<br/>被禁止访问时间：{3}<br/>解除禁止访问时间：{4}<br/><br/><br/>Powered by <font color='blue'>(网站禁止访问功能模块)Kvkens</font>", context.Request.UserHostAddress, list.Operate, list.Description, list.LimitDate.ToString(), list.RemoveDate.ToString()));
                        context.Response.End();
                    }
                }
            }
        }

        #endregion
    }
}
